#include <iostream>
#include <math.h>
using namespace std;
int inf=0x7fffffff;


int dfs(int n,int k){
	if(n == k)
		return 0;
	if(n < 0)
		return -1;
	int l,ans=inf;
	l = dfs(n-1,k);
	if(l != -1)
		ans = l;
	l = dfs(n+1,k);
	if(l != -1)
		ans = min(ans,l);
	l = dfs(n*2,k);
	if(l != -1)
		ans = min(ans,l);
	if(ans != inf)
		return ans+1;
	else
		return -1;
}


int main(){
	int n,k;
	cin>>n>>k;
	cout<<dfs(n,k);
	return 0;
}
